package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    void insert(Orders orders);

    void update(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus},checkout_time = #{checkOutTime} where id = #{id}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime checkOutTime, Long id);


    @Select("select * from orders where status = #{status}")
    Page<Orders> selectByStatus(Integer status);


    @Select("select * from orders where id = #{id}")
    Orders selectById(Long id);

    Page<Orders> select(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from orders")
    List<Orders> selectAll();


    @Select("select * from orders where status = #{status} and order_time <  #{time}")
    List<Orders> selectTimeoutByStatus(Integer status,LocalDateTime time);

    @Select("select * from orders where status =#{deliveryInProgress} and  order_time <#{time}")
    List<Orders> getByStatusAndOrderTime(Integer deliveryInProgress, LocalDateTime time);


    Double selectSumAmount(LocalDateTime beginTime, LocalDateTime endTime);
}
